<template>
  <div id="grade">
    <app-scroll class="content">
      <div class="wrap">
        <div class="topbg">
          <h3><span @click="toback"> ＜ </span> 积分商城</h3>
          <div class="banner">
            <img
              src="img/banner5.png"
              alt=""
            />
          </div>
        </div>
        <div class="bodycontent">
          <div class="nav">
            <li>
              <span><img src="img/four.png" alt=""></span>
              <i>每日签到</i>
            </li>
            <li>
              <span><img src="img/three.png" alt=""></span>
              <i>我的积分</i>
            </li>
            <li>
              <span><img src="img/two.png" alt=""></span>
              <i>我的收藏</i>
            </li>
            <li>
              <span><img src="img/first.png" alt=""></span>
              <i>兑换记录</i>
            </li>
          </div>
          <div class="activity">
            <h6><i>活动专场</i><span>更多</span></h6>
            <div class="allgoods">
              <li v-for="item in goods" :key="item.id">
                <img :src="item.airImage" alt="" />
                <div class="introduction">
                  <p>{{ item.title }}</p>
                  <h1>限量{{ item.limit }}</h1>
                  <h2>{{ item.has }} 人已领</h2>
                  <h3>{{ item.grade }} 积分</h3>
                  <h4 @click="changeAction(item.id)">立即兑换</h4>
                </div>
              </li>
            </div>
          </div>
        </div>
      </div>
    </app-scroll>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      goods: {},
      id:[]
    };
  },
  methods: {
    async requestShopMsg() {
      const {
        data: { data },
      } = await axios.get("data/grade.json");
      // console.log(ms)
      this.goods = data;
    },
    toback(){
        this.$router.back();
    },
    changeAction(id){
      this.$router.push({name:"Mine",params:{id}})
        if(localStorage.getItem("gradeid")){
          this.id = JSON.parse(localStorage.getItem("gradeid"));
          var result=this.id.filter(item=>{
              if(item.id===id){
                  item.num++;
              }
              return item.id===id;
          })
          if(result.length===0){
              this.id.push({id:id,num:1});

          }
          localStorage.setItem('gradeid',JSON.stringify(this.id));
      }else{
          this.id.push({id:id,num:1});
          localStorage.setItem('gradeid',JSON.stringify(this.id))
      }
    }
  },
  mounted() {
    this.requestShopMsg();
  },
};
</script>

<style lang="scss" scoped>
#grade {
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  bottom: 0;
}
.content {
  height: 100%;
  width: 100%;
}

.topbg {
  height: 200px;
  width: 100%;
  background: rgba(48, 48, 48, 1);
  h3 {
    height: 50px;
    text-align: center;
    line-height: 50px;
    font-size: 18px;
    color: #fff;
    position: relative;
    span {
      position: absolute;
      left: 20px;
    }
  }
  .banner {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 10px;
    overflow: hidden;
    img {
      width: 95%;
      height: 150px;
      border-radius: 8px;
    }
  }
}
.bodycontent {
  width: 100%;
  background: rgba(247, 247, 248, 1);
  border-radius: 50% 50% 0 0/50px 50px 0 0;
  margin-top: -50px;
  padding: 80px 0 0 0;
  .nav {
    height: 70px;
    width: 100%;
    display: flex;
    justify-content: space-around;
    li {
      display: flex;
      align-items: center;
      flex-direction: column;
      span {
        display: block;
        height: 45px;
        width: 45px;
        background: #ddd;
        margin-bottom: 3px;
        border-radius: 50%;
        img{
          height: 45px;
          width: 45px;
         border-radius: 50%;
        }
      }
    }
  }
  .activity {
    border-top: 20px solid #eee;
    width: 100%;
    h6 {
      height: 50px;
      display: flex;
      align-items: center;
      box-sizing: border-box;
      padding: 0 20px;
      justify-content: space-between;
      i {
        font-size: 16px;
        color: #333;
        font-weight: 700;
      }
      span {
        font-size: 12px;
        color: #ff3333;
      }
    }
    .allgoods {
      li {
        display: flex;
        padding: 10px 20px;
        img {
          width: 90px;
        }
        .introduction {
          display: flex;
          flex-direction: column;
          margin-left: 15px;
          justify-content: space-between;
          position: relative;
          width: 245px;
          p{
              font-size: 14px;
              font-weight: 700;
              color:#515151
          }
          h1{
              height: 25px;
              line-height: 25px;
              width: 70px;
              text-align: center;
              border-radius: 5px;
              border: 1pX solid #FF0000;
              color: #FF0000;
          }
          h2{
              color: #aaa;
              font-size: 12px;
          }
          h3{
              color: #FF0000;
              font-size: 14px;
              font-weight: 700;
          }
          h4{
              position: absolute;
              right: 0;
              bottom: 0;
              width: 76px;
              height: 27px;
              line-height: 27px;
              font-family: '微软雅黑 Bold', '微软雅黑 Regular', '微软雅黑';
              font-weight: 700;
              font-style: normal;
              font-size: 12px;
              color: #FF0000;
              padding: 0;
              background-color: rgba(255, 235, 232, 1);
              text-align: center;
              border-radius: 8px;
          }
        }
      }
    }
  }
}
</style>